﻿using MediatR;
using Ordering.Domain.Aggregate;

namespace Ordering.Application.Commands
{
    public class PaymentOrderCommand : IRequest
    {
        public string Id { get; set; }
    }

    public class PaymentOrderCommandHandler
        : IRequestHandler<PaymentOrderCommand>
    {
        private readonly IOrderStogage _orderStogage;

        public PaymentOrderCommandHandler(IOrderStogage orderStogage)
        {
            _orderStogage = orderStogage;
        }

        public async Task Handle(PaymentOrderCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderStogage.GetByIdAsync(request.Id);
            order.Paymeny();
            _orderStogage.Update(order);
            await _orderStogage.UnitOfWork.SaveEntitiesAsync(cancellationToken);
        }
    }
}
